﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using ESOL.Common.Entity;
using ESOL.Business.Mst;
using ESOL.WinUI.Hr;

namespace ESOL.WinUI.Manufacture
{
    public partial class frmMaintainWorkingGroupQuery : BaseForm.frmBaseDialogyQueryForm
    {
        #region vars
        //public MstWorkingGroupEntity SelectedMstWorkingGroup { set; get; }
        public MstWorkingGroupPersonEntity SelectedMstWorkingGroupPerson { get { return _SelectedMstWorkingGroupPerson; } }
        private MstWorkingGroupPersonEntity _SelectedMstWorkingGroupPerson;
        private List<MstWorkingGroupEntity> ListMstWorkingGroup;
        #endregion

        #region ctors
        public frmMaintainWorkingGroupQuery()
        {
            InitializeComponent();
        }
        #endregion

        #region functions
        private void BindGridData()
        {
            DataTable dt = MstWorkingGroupBs.GetDtMstWorkingGroupByCondition("","");
            gvMain.DataSource = dt;
        }
        #endregion

        #region events
        protected override void OnShown(EventArgs e)
        {
            base.OnShown(e);
            BindGridData();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            DataRow dr = gridView1.GetDataRow(e.RowHandle);
            _SelectedMstWorkingGroupPerson = new MstWorkingGroupPersonEntity(dr);
        }

        private void gridView1_DoubleClick(object sender, EventArgs e)
        {
            if (_SelectedMstWorkingGroupPerson == null)
            {
                MessageBox.Show("请选择一个工作组类别！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        protected override void Click_Confirm()
        {
            if (SelectedMstWorkingGroupPerson == null)
            {
                MessageBox.Show("请选择一个工作组！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.DialogResult = DialogResult.OK;
        }

        private void txtGroupLead_KeyUp(object sender, KeyEventArgs e)
        {
            frmMaintainEmployeeQuery frm = new frmMaintainEmployeeQuery();
            if (frm.ShowDialog() == DialogResult.OK && frm.SelectedPerson != null)
            {
                txtGroupLead.Text = frm.SelectedPerson.NameCn;
                txtGroupLead.Tag = frm.SelectedPerson;
            }
        }

        protected override void Click_Query()
        {
            string Condition = "";
            if (string.IsNullOrEmpty(txtGroup.Text) == false)
                Condition += " AND MWG.GROUP_NAME LIKE '%" + txtGroup.Text + "%' ";
            if (string.IsNullOrEmpty(txtGroupLead.Text) == false)
                Condition += " AND MWG.GROUP_LEADOR='" + ((MstPersonEntity)txtGroupLead.Tag).PersonId;
            DataTable dt = MstWorkingGroupBs.GetDtMstWorkingGroupByCondition(Condition, "");
            gvMain.DataSource = dt;
        }
        #endregion


    }
}
